/* =========================================================
Home page slider
============================================================ */
jQuery(window).load(function(){
  jQuery('#main-slider').flexslider({
	animation: "slide",
	reverse: false,
	start: function(slider){
	  jQuery('body').removeClass('loading');
	}
  });
  
});

/* =========================================================
Twitter
============================================================ */
	 jQuery(function(jQuery){
        jQuery("#custom").tweet({
          avatar_size: 32,
          count: 2,
          username: "envato",
          template: "{text} » {retweet_action}"
        });
      }).bind("loaded", function(){
        jQuery(this).find("a.tweet_action").click(function(ev) {
          window.open(this.href, "Retweet",
                      'menubar=0,resizable=0,width=550,height=420,top=200,left=400');
          ev.preventDefault();
        });
      });

    
/* =========================================================
Social icons hover
============================================================ */
jQuery(document).ready(function(){
   
    jQuery(".social-links a").mouseenter(function(){
        jQuery(this).find('img').fadeTo(300, 0);
    }).mouseleave(function(){
        jQuery(this).find('img').fadeTo(300, 1);
    });	
});
/* =========================================================
Fix css
============================================================ */
jQuery(document).ready(function(){
	jQuery(".older-post li:last-child").css("border-bottom",'none');
	jQuery(".older-post li:last-child").css("padding-bottom",0);
	jQuery(".older-post li:last-child").css("margin-bottom",0);
	jQuery("#bottom-sidebar .widget ul li:last-child").css("background",'none');
	jQuery(".sidebar-tab-content ul li:last-child").css("border-bottom",'none');
});
/* =========================================================
Create mobile menu
============================================================ */
function createMobileMenu(menu_id, mobile_menu_id){
    // Create the dropdown base
    jQuery("<select />").appendTo(menu_id);
    jQuery(menu_id).find('select').first().attr("id",mobile_menu_id);
    
    // Populate dropdown with menu items
    jQuery(menu_id).find('a').each(function() {        
        var el = jQuery(this);       
        
        var selected = '';
        if (el.parent().hasClass('current-menu-item') == true){
            selected = "selected='selected'";
        }        
        
        var depth = el.parents("ul").size();
        var space = '';
        if(depth > 1){
            for(i=1; i<depth; i++){
                space += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
            }
        }        
        
        jQuery("<option "+selected+" value='"+el.attr("href")+"'>"+space+el.text()+"</option>").appendTo(jQuery(menu_id).find('select').first());
    });
    jQuery(menu_id).find('select').first().change(function() {
        window.location = jQuery(this).find("option:selected").val();
    });    
}

jQuery(document).ready(function(){
    if(jQuery('#main-nav').length > 0){
        createMobileMenu('#main-nav','responsive-menu');	
    }
});
jQuery(document).ready(function(){
    if(jQuery('#top-nav').length > 0){
        createMobileMenu('#top-nav','top-responsive-menu');	
    }
});

/* =========================================================
Dropdown menu
============================================================ */
jQuery(document).ready(function(){
	
	jQuery("#main-menu li").hover(function() {
		jQuery(this).find("ul").first().slideDown(300);
			}, function() {
		jQuery(this).find("ul").first().hide();
	});

})
/* =========================================================
HeadLines Scroller
============================================================ */
jQuery(document).ready(function() {

	//create scroller for each element with "horizontal_scroller" class...
	jQuery('.horizontal_scroller').SetScroller({	velocity: 	 60,
											direction: 	 'horizontal',
											startfrom: 	 'right',
											loop:		 'infinite',
											movetype: 	 'linear',
											onmouseover: 'pause',
											onmouseout:  'play',
											onstartup: 	 'play',
											cursor: 	 'pointer'
										});
	/*
		All possible values for options...
		
		velocity: 		from 1 to 99 								[default is 50]						
		direction: 		'horizontal' or 'vertical' 					[default is 'horizontal']
		startfrom: 		'left' or 'right' for horizontal direction 	[default is 'right']
						'top' or 'bottom' for vertical direction	[default is 'bottom']
		loop:			from 1 to n+, or set 'infinite'				[default is 'infinite']
		movetype:		'linear' or 'pingpong'						[default is 'linear']
		onmouseover:	'play' or 'pause'							[default is 'pause']
		onmouseout:		'play' or 'pause'							[default is 'play']
		onstartup: 		'play' or 'pause'							[default is 'play']
		cursor: 		'pointer' or any other CSS style			[default is 'pointer']
	*/

});
/* =========================================================
Featured news slider

jQuery(window).load(function() {
	
	jQuery('.feature-news').carouFredSel({
		responsive: true,
		prev: '#prev-2',
		next: '#next-2',
		width: '100%',				
		scroll: 1,
		auto: false,
		items: {
			width: 226,
			height: "auto",
			visible: {				
				min: 1,
				max: 3
			}
		}
	});
	jQuery('.related-articles').carouFredSel({
		responsive: true,
		prev: '#prev-3',
		next: '#next-3',
		width: '100%',		
		scroll: 1,
		auto: false,
		items: {
			width: 226,
			height: "auto",
			visible: {
				min: 1,
				max: 3
			}
		}
	});
});
============================================================ */
/* 
=========================================================
Tabs
============================================================ 
jQuery(document).ready(function() {    
    if( jQuery(".tab-content").length > 0){   
        //Default Action Product Tab
        jQuery(".tab-content").hide(); //Hide all content
        jQuery("ul.tabs li:first").addClass("active").show(); //Activate first tab
        jQuery(".tab-content:first").show(); //Show first tab content
        //On Click Event Product Tab
        jQuery("ul.tabs li").click(function() {
            jQuery("ul.tabs li").removeClass("active"); //Remove any "active" class
            jQuery(this).addClass("active"); //Add "active" class to selected tab
            jQuery(".tab-content").hide(); //Hide all tab content
            var activeTab = jQuery(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
            jQuery(activeTab).fadeIn(); //Fade in the active content
            return false;
		
        });
    }
	
	if( jQuery(".sidebar-tab-content").length > 0){   
        //Default Action Product Tab
        jQuery(".sidebar-tab-content").hide(); //Hide all content
        jQuery("ul.sidebar-tabs li:first").addClass("active").show(); //Activate first tab
        jQuery(".sidebar-tab-content:first").show(); //Show first tab content
        //On Click Event Product Tab
        jQuery("ul.sidebar-tabs li").click(function() {
            jQuery("ul.sidebar-tabs li").removeClass("active"); //Remove any "active" class
            jQuery(this).addClass("active"); //Add "active" class to selected tab
            jQuery(".sidebar-tab-content").hide(); //Hide all tab content
            var activeTab = jQuery(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
            jQuery(activeTab).fadeIn(); //Fade in the active content
            return false;
		
        });
    }
});
*/
/* =========================================================
Flickr Feed
============================================================ */
jQuery(document).ready(function(){ 
	jQuery('#flickr-feed-1').jflickrfeed({
		limit: 8,
		qstrings: {
			id: '78715597@N07'
		},
		itemTemplate:
			'<li class="flickr-badge-image">' +
			'<a rel="prettyPhoto[kopa-flickr]" href="{{image}}" title="{{title}}">' +
			'<img src="{{image_s}}" alt="{{title}}" width="66px" heigth="66px" />' +
			'</a>' +
			'</li>'
	}, function(data) {
			jQuery("a[rel^='prettyPhoto']").prettyPhoto({
			show_title: false,
			deeplinking:false
		}).mouseenter(function(){
			//jQuery(this).find('img').fadeTo(500, 0.6);
		}).mouseleave(function(){
			//jQuery(this).find('img').fadeTo(400, 1);
		});
	});
});

/* =========================================================
Image hover effect
============================================================ */
jQuery(document).ready(function(){
	  jQuery(".box-image").mouseenter(function(){
        jQuery(this).fadeTo(500, 0.4);
    }).mouseleave(function(){
        jQuery(this).fadeTo(500, 1);
    });	
});
/* =========================================================
Scroll to top
============================================================ */
jQuery(document).ready(function(){

	// hide #back-top first
	jQuery("#back-top").hide();
	
	// fade in #back-top
	jQuery(function () {
		jQuery(window).scroll(function () {
			if (jQuery(this).scrollTop() > 100) {
				jQuery('#back-top').fadeIn();
			} else {
				jQuery('#back-top').fadeOut();
			}
		});

		// scroll body to 0px on click
		jQuery('#back-top a').click(function () {
			jQuery('body,html').animate({
				scrollTop: 0
			}, 800);
			return false;
		});
	});

});
/* =========================================================
Hover effect
============================================================ */
jQuery(document).ready(function(){   
    jQuery(".hover-effect").mouseenter(function(){
        jQuery(this).fadeTo(300, 0.8);
    }).mouseleave(function(){
        jQuery(this).fadeTo(300, 1);
    });	
});

/*
 =========================================================
prettyPhoto
============================================================ 
jQuery(document).ready(function(){
    jQuery("a[rel^='prettyPhoto']").prettyPhoto({
		show_title: false,
		deeplinking:false
		});
});
*/
/* =========================================================
Fix height of one-forth column in Bottom Sidebar
============================================================ */

function fix_column_height(){
	child=jQuery("#bottom-sidebar .container .one-forth");
	max_height=jQuery("#bottom-sidebar .container .one-forth").first().height();
	jQuery.each( child, function(){
		 if(jQuery(this).height() > max_height){
			 max_height=jQuery(this).height();
		 }
	});	
	jQuery.each( child, function(){
		 jQuery(this).height(max_height);
	});	
}
jQuery(document).ready(function(){
    fix_column_height();  
});
jQuery(window).resize(function() {
	 fix_column_height(); 
});
/* =========================================================
Comment Form
============================================================ */
jQuery(document).ready(function() {
    var validator = jQuery("#comments-form").kendoValidator().data("kendoValidator"),
    status = jQuery("#status-message");
    jQuery("#submit-comment").click(function() {
        if (validator.validate()) {
            status.text("Your message is being sent").addClass("valid");
        } else {
            status.text("Oops! There is invalid data in the form.").addClass("invalid");
        }
    });
});
